package com.tct.worktimeboard.controller;

import com.alibaba.fastjson.JSONObject;
import com.tct.worktimeboard.entity.WorkGroup;
import com.tct.worktimeboard.entity.WorkGroupVO;
import com.tct.worktimeboard.service.IWorkGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Huhailong
 * @Description
 * @Date 2021/2/23.
 */
@RestController
@RequestMapping("/workGroup")
public class WorkGroupController {

    @Autowired
    IWorkGroupService workGroupService;

    @PostMapping("/createGroup")
    public JSONObject createGroup(@RequestBody WorkGroupVO workGroupVO){
        return workGroupService.createGroup(workGroupVO);
    }

    @GetMapping("/getGroupList")
    public JSONObject getGroupList(WorkGroup group){
        return workGroupService.getGroupList(group);
    }

    @PostMapping("deleteGroup")
    public JSONObject deleteGroup(@RequestBody List<Long> ids){
        return workGroupService.deleteGroup(ids);
    }

    @PostMapping("updateGroup")
    public JSONObject updateGroup(@RequestBody WorkGroupVO workGroupVO){
        return workGroupService.updateGroup(workGroupVO);
    }

    @GetMapping("/getUserByGroup")
    public JSONObject getUserByGroup(Long groupId){
        return workGroupService.getUserByGroup(groupId);
    }

    @GetMapping("/getPowerUserByGroup")
    public JSONObject getPowerUserByGroup(Long groupId){
        return workGroupService.getPowerUserByGroup(groupId);
    }

    @GetMapping("/getGroupIdListByUserId")
    public JSONObject getGroupIdListByUserId(Long userId){
        return workGroupService.getGroupIdListByUserId(userId);
    }

    @GetMapping("/getGroupPowerByUserId")
    public JSONObject getGroupPowerByUserId(Long userId){
        return workGroupService.getGroupPowerUserId(userId);
    }

    @GetMapping("/getGroupListByUserId")
    public JSONObject getGroupListByUserId(HttpServletRequest request){
        String userId = request.getHeader("userId");
        return workGroupService.getGroupByUserId(Long.valueOf(userId));
    }
}
